* Multiproduct Firms, Horizontal Mergers, and International Trade
* Jackie M.L. Chan, Michael Irlacher, and Michael Koch

* This do file runs additional regressions for domestic market outcomes.

* Setup
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_mergers_all_largestT_1865.dta", clear
rename aar aar_ori
expand 27
bysort cvrnrA aar_ori cvrnrT: gen aar = 1991 + _n
rename cvrnrT cvrnr
merge 1:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_firm_subset1865.dta", keep(match) 
collapse (sum) employee_cvrnr OMS_FIRM, by(cvrnrA aar_ori aar)
rename aar aarA
rename aar_ori aar
rename employee_cvrnr employee_cvrnr_tgt
rename OMS_FIRM OMS_FIRM_tgt
tempfile tempe
save `tempe.dta', replace

* Main data
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\regression_data_domestic.dta", clear

merge 1:1 cvrnrA aar aarA using `tempe.dta', keep(match master)

egen maxaarAin = max(aarA) if _merge==3, by(cvrnrA aar)
egen minaarAin = min(aarA) if _merge==3, by(cvrnrA aar)
drop _merge

gen OMS_FIRM_tgt0 = OMS_FIRM_tgt if aarA==minaarAin
gen OMS_FIRM_tgt1 = OMS_FIRM_tgt if aarA==maxaarAin
egen mOMS_FIRM_tgt0 = mean(OMS_FIRM_tgt0), by(cvrnrA)
egen mOMS_FIRM_tgt1 = mean(OMS_FIRM_tgt1), by(cvrnrA)
gen OMS_FIRM_tgt_gr = (mOMS_FIRM_tgt1/mOMS_FIRM_tgt0-1)

* Figure A.16(a), (b), (c)
foreach x in lnnprod{
did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & OMS_FIRM_tgt_gr>0) | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA16.txt", bdec(4) sdec(4) nocons nonotes

did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & OMS_FIRM_tgt_gr<=0) | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA16.txt", bdec(4) sdec(4) nocons nonotes
}

foreach x in lnnprodAT_nodup{	
did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & ((nprodT>0 & d_yr<=0) | d_yr>0) & OMS_FIRM_tgt_gr>0) | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA16.txt", bdec(4) sdec(4) nocons nonotes

did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & ((nprodT>0 & d_yr<=0) | d_yr>0) & OMS_FIRM_tgt_gr<=0) | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA16.txt", bdec(4) sdec(4) nocons nonotes
}

foreach x in theil_fy{
did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & OMS_FIRM_tgt_gr>0) | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA16.txt", bdec(4) sdec(4) nocons nonotes

did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & OMS_FIRM_tgt_gr<=0) | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA16.txt", bdec(4) sdec(4) nocons nonotes
}
